const VALIDPHONE = {
  reg: /^[1][0-9]{2}[0-9]{4}[0-9]{4}$/,
  errMsg: '请输入正确的手机号',
  required: '请输入手机号'
}
const VALIDNAME = {
  reg: /^([\u4e00-\u9fa5]){2,8}$/,
  errMsg: '请输入2-8个汉字'
}
const VALIDENGNAME = {
  reg: /^[a-zA-Z \s]{2,20}$/,
  errMsg: '请输入2-20个字母'
}
const VALIDCODE = {
  reg: /^[0-9]{4}$/,
  errMsg: '验证码不正确',
  required: '请输入验证码'
}
const VALIDREQUIRED = {
  errMsg: '必填'
}
const VALIDPWD = {
  reg: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/,
  errMsg: '密码为6-12位数字字母组合',
  required: '请输入密码'
}
const VALIDATOR = (valid, value) => {
  let msg;
  for (const key in valid) {
    if (key === 'required') {
      if (!value.toString().trim().length) {
        msg = valid[key].errMsg
        break;
      }
    }
    if (key === 'valid') {
      if (!valid[key].reg.test(value)) {
        msg = valid[key].errMsg
        break;
      }
    }
  }
  return msg
}
export {
  VALIDPHONE,
  VALIDREQUIRED,
  VALIDNAME,
  VALIDPWD,
  VALIDCODE,
  VALIDATOR,
  VALIDENGNAME
}